//
//  SPTabBarController.m
//  ShopProject
//
//  Created by kuangbiao on 2018/11/26.
//  Copyright © 2018 KB. All rights reserved.
//

#import "SPTabBarController.h"
#import "SPNavigationViewController.h"
#import "SPHomeViewController.h"
#import "SPShoppingCartViewController.h"
#import "SPCustomerServiceViewController.h"
#import "SPMineViewController.h"

@interface SPTabBarController ()

@end

@implementation SPTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadTabBarViewControllers];
    [self configTabBarItem];
    self.tabBar.barStyle = UIBarStyleBlack;
//    self.tabBar.layer.shadowColor = [UIColor colorWithHexString:@"cccccc"].CGColor;
//
//    self.tabBar.layer.shadowOffset = CGSizeMake(0, -1);
//
//    self.tabBar.layer.shadowOpacity =0.32;
}

- (void)loadTabBarViewControllers{
    
    SPHomeViewController *homePageVC = [[SPHomeViewController alloc] initWithNibName:@"SPHomeViewController" bundle:nil];
    SPNavigationViewController *homePageNav = [[SPNavigationViewController alloc] initWithRootViewController:homePageVC];
    [homePageVC setTitle:@"首页"];
    homePageNav.tabBarItem.image = [UIImage imageNamed:@"home_icon_24x24_"];
    homePageNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"home_icon_selected_24x24_"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homePageNav.tabBarItem.title = @"首页";
    
    
    SPShoppingCartViewController *shoppingVC = [[SPShoppingCartViewController alloc] initWithNibName:@"SPShoppingCartViewController" bundle:nil];
    SPNavigationViewController *shopNav = [[SPNavigationViewController alloc] initWithRootViewController:shoppingVC];
    [shoppingVC setTitle:@"交流"];
    shopNav.tabBarItem.image = [UIImage imageNamed:@"tab_icon_shequ_24x24_"];
    shopNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tab_icon_shequ_selected_24x24_"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    shopNav.tabBarItem.title = @"交流";
    
    SPCustomerServiceViewController *servericeVC = [[SPCustomerServiceViewController alloc] initWithNibName:@"SPCustomerServiceViewController" bundle:nil];
    SPNavigationViewController *serviceNav = [[SPNavigationViewController alloc] initWithRootViewController:servericeVC];
    [servericeVC setTitle:@"消息"];
    serviceNav.tabBarItem.image = [UIImage imageNamed:@"message_icon_24x24_"];
    serviceNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"message_icon_selected_24x24_"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    serviceNav.tabBarItem.title = @"消息";
    
    SPMineViewController *mineVC = [[SPMineViewController alloc] initWithNibName:@"SPMineViewController" bundle:nil];
    SPNavigationViewController *mineNav = [[SPNavigationViewController alloc] initWithRootViewController:mineVC];
    [mineVC setTitle:@"我的"];
    mineNav.tabBarItem.image = [UIImage imageNamed:@"mine_icon_24x24_"];
    mineNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"mine_icon_selected_24x24_"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    mineNav.tabBarItem.title = @"我的";
    
    SPMineViewController *mineVC1 = [[SPMineViewController alloc] initWithNibName:@"SPMineViewController" bundle:nil];
    SPNavigationViewController *mineNav1 = [[SPNavigationViewController alloc] initWithRootViewController:mineVC1];
    [mineVC1 setTitle:@"我的"];
    mineNav1.tabBarItem.image = [UIImage imageNamed:@"mine_icon_24x24_"];
    mineNav1.tabBarItem.selectedImage = [[UIImage imageNamed:@"mine_icon_selected_24x24_"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    mineNav1.tabBarItem.title = @"我的";
    [self setViewControllers: @[homePageNav,shopNav,serviceNav,mineNav,mineNav1] animated:YES];
}

#pragma mark - configurate tabBarItem
- (void)configTabBarItem{
    //tabbar默认显示的图片根据自己设置的定义
    for (UITabBarItem *item in self.tabBar.items) {
        item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = [item.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    
    //设置TabBar背景颜色
    [self.tabBar setBackgroundColor:[UIColor whiteColor]];
    [self.tabBar setBarTintColor:[UIColor whiteColor]];
    self.tabBar.translucent = NO;
    self.tabBar.layer.borderWidth = 0.50;
    self.tabBar.layer.borderColor = [UIColor colorWithRed:206/255.0 green:206/255.0 blue:206/255.0 alpha:1].CGColor;
    self.tabBar.barStyle = UIBarStyleBlackOpaque;
    
    //设置TabBarItem字体大小和颜色
    //正常状态
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"999999"],NSFontAttributeName:[UIFont systemFontOfSize:10.0f]} forState:UIControlStateNormal];
    
    //选中状态
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"333333"],NSFontAttributeName:[UIFont systemFontOfSize:10.0f]} forState:UIControlStateSelected];
}

@end
